From 0c373adfd41f408bf61f9e984eb76f2bb53033a0 Mon Sep 17 00:00:00 2001 From: "mjw@wray-m-3.hpl.hp.com" Date: Mon, 12 Jul 2004 17:20:22 +0000 Subject: [PATCH] bitkeeper revision 1.1062.3.7 (40f2c856i0jGNAZ3xZZ9fZILH7YDhw) Fix sxpr conversion for forms. Fix args for restore. --- tools/python/xen/xend/Args.py | 47 ++++++++++++++--------- tools/python/xen/xend/XendClient.py | 14 +++---- tools/python/xen/xend/server/SrvDomain.py | 3 +- 3 files changed, 38 insertions(+), 26 deletions(-) diff --git a/tools/python/xen/xend/Args.py b/tools/python/xen/xend/Args.py index 31bc067d07..f70000a9d5 100644 --- a/tools/python/xen/xend/Args.py +++ b/tools/python/xen/xend/Args.py @@ -1,4 +1,6 @@ import types +import StringIO + import sxp class ArgError(StandardError): @@ -50,39 +52,48 @@ class Args: def get_form_args(self, f, xargs=None): d = {} for (k, v) in f.items(): - n = len(v) if ((k not in self.arg_dict) and (k not in self.key_dict)): continue - if n == 0: - continue - elif n == 1: - d[k] = v[0] + if isinstance(v, types.ListType): + n = len(v) + if n == 0: + continue + elif n == 1: + val = v[0] + else: + raise ArgError('Too many values for %s' % k) else: - raise ArgError('Too many values for %s' % k) + val = v + d[k] = val return self.get_args(d, xargs=xargs) def coerce(self, type, v): try: if type == 'int': - return int(v) - if type == 'str': - return str(v) - if type == 'sxpr': - return self.sxpr(v) + val = int(v) + elif type == 'str': + val = str(v) + elif type == 'sxpr': + val = self.sxpr(v) + else: + raise ArgError('invalid type:' + str(type)) + return val except ArgError: raise except StandardError, ex: raise ArgError(str(ex)) def sxpr(self, v): - if instanceof(v, types.ListType): - return v - if instanceof(v, types.File) or hasattr(v, 'readline'): - return sxpr_file(v) - if instanceof(v, types.StringType): - return sxpr_file(StringIO(v)) - return str(v) + if isinstance(v, types.ListType): + val = v + elif isinstance(v, types.FileType) or hasattr(v, 'readline'): + val = self.sxpr_file(v) + elif isinstance(v, types.StringType): + val = self.sxpr_file(StringIO.StringIO(v)) + else: + val = str(v) + return val def sxpr_file(self, fin): try: diff --git a/tools/python/xen/xend/XendClient.py b/tools/python/xen/xend/XendClient.py index 817d2818ce..3f9c417334 100644 --- a/tools/python/xen/xend/XendClient.py +++ b/tools/python/xen/xend/XendClient.py @@ -222,14 +222,19 @@ class Xend: {'op' : 'create', 'config' : fileof(conf) }) - def xend_domain(self, id): - return xend_get(self.domainurl(id)) + def xend_domain_restore(self, filename): + return xend_call(self.domainurl(), + {'op' : 'restore', + 'file' : filename }) def xend_domain_configure(self, id, config): return xend_call(self.domainurl(id), {'op' : 'configure', 'config' : fileof(conf) }) + def xend_domain(self, id): + return xend_get(self.domainurl(id)) + def xend_domain_unpause(self, id): return xend_call(self.domainurl(id), {'op' : 'unpause'}) @@ -252,11 +257,6 @@ class Xend: {'op' : 'save', 'file' : filename}) - def xend_domain_restore(self, id, filename): - return xend_call(self.domainurl(id), - {'op' : 'restore', - 'file' : filename }) - def xend_domain_migrate(self, id, dst): return xend_call(self.domainurl(id), {'op' : 'migrate', diff --git a/tools/python/xen/xend/server/SrvDomain.py b/tools/python/xen/xend/server/SrvDomain.py index cb70cf41bc..80cda0d022 100644 --- a/tools/python/xen/xend/server/SrvDomain.py +++ b/tools/python/xen/xend/server/SrvDomain.py @@ -19,9 +19,10 @@ class SrvDomain(SrvDir): self.xconsole = XendConsole.instance() def op_configure(self, op, req): + print 'op_configure>', op, req.args fn = FormFn(self.xd.domain_configure, [['dom', 'int'], - ['config', 'sxp']]) + ['config', 'sxpr']]) val = fn(req.args, {'dom': self.dom.id}) #todo: may need to add ok and err callbacks. return val -- 2.30.2